﻿using System;
using System.Collections;
using Assets.Scripts.GtsScripts;
using UnityEngine;

// Token: 0x020002A1 RID: 673
public abstract class RaygunProjectile : Projectile
{
	// Token: 0x06000F11 RID: 3857 RVA: 0x000732F0 File Offset: 0x000714F0
	protected override void Start()
	{
		base.Start();
		this.trail.startWidth *= base.transform.localScale.x;
		this.trail.endWidth *= base.transform.localScale.x;
		this.trail.time *= base.transform.localScale.x;
	}

	// Token: 0x06000F12 RID: 3858 RVA: 0x00073374 File Offset: 0x00071574
	private void Update()
	{
		if (!this.alive)
		{
			return;
		}
		base.transform.position += base.transform.forward * this.baseSpeed * Time.deltaTime;
		this.lifeTime -= Time.deltaTime;
		if (this.lifeTime < 0f)
		{
			this.Explode(0.25f);
		}
	}

	// Token: 0x06000F13 RID: 3859 RVA: 0x000733F0 File Offset: 0x000715F0
	protected override void Impact(GameObject hitObject)
	{
		float scaleMult = 0.25f;
		if (hitObject.GetComponent<Giantess>() != null)
		{
			scaleMult = 10f * Mathf.Log(hitObject.transform.localScale.x + 1f, 2f);
		}
		this.Explode(scaleMult);
	}

	// Token: 0x06000F14 RID: 3860 RVA: 0x00073448 File Offset: 0x00071648
	protected void Explode(float scaleMult)
	{
		this.alive = false;
		this.audioSource.Play();
		IEnumerator enumerator = base.gameObject.transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform = (Transform)obj;
				UnityEngine.Object.Destroy(transform.gameObject);
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		base.gameObject.GetComponent<CapsuleCollider>().enabled = false;
		base.gameObject.GetComponent<Rigidbody>().detectCollisions = false;
		this.projectileModelRenderer.enabled = false;
		if (this.createImpactParticles)
		{
			float scale = scaleMult * 5f * this.particlesScaleMult;
			this.CreateImpactParticles(scale);
		}
		UnityEngine.Object.Destroy(base.gameObject, 3f);
	}

	// Token: 0x06000F15 RID: 3861 RVA: 0x00073528 File Offset: 0x00071728
	private void CreateImpactParticles(float scale)
	{
		GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.impactParticlesTemplate, base.transform.position, Quaternion.identity);
		gameObject.transform.localScale = new Vector3(scale, scale, scale);
		ParticleSystem component = gameObject.GetComponent<ParticleSystem>();
		Gradient gradient = new Gradient();
		gradient.SetKeys(new GradientColorKey[]
		{
			new GradientColorKey(this.mainColor, 0f),
			new GradientColorKey(this.mainColor, 1f)
		}, new GradientAlphaKey[]
		{
			new GradientAlphaKey(0f, 0f),
			new GradientAlphaKey(0.9f, 0.5f),
			new GradientAlphaKey(0f, 1f)
		});
		component.colorOverLifetime.color = gradient;
		ParticleSystem.MinMaxCurve size = component.sizeOverLifetime.size;
		size.constantMin *= scale;
		size.constantMax *= scale;
		component.Emit(40);
		UnityEngine.Object.Destroy(gameObject, component.main.duration);
	}

	// Token: 0x06000F16 RID: 3862 RVA: 0x0007366C File Offset: 0x0007186C
	protected override void SetColor(Color color, float emissionModifier = 1f)
	{
		this.mainColor = color;
		Vector4 v = new Vector4(color.r, color.g, color.b, 0f) * (Mathf.Log(Mathf.Abs(emissionModifier) + 1.3f, 2.3f) * 2f);
		Material material = this.projectileModelRenderer.material;
		material.color = color;
		material.SetColor("_EmissionColor", v);
		Material material2 = this.trail.material;
		material2.SetColor("_Color", color);
		material2.SetColor("_EmissionColor", v);
	}

	// Token: 0x04001406 RID: 5126
	[SerializeField]
	private GameObject impactParticlesTemplate;

	// Token: 0x04001407 RID: 5127
	[SerializeField]
	private TrailRenderer trail;

	// Token: 0x04001408 RID: 5128
	[SerializeField]
	private Renderer projectileModelRenderer;

	// Token: 0x04001409 RID: 5129
	protected bool createImpactParticles;

	// Token: 0x0400140A RID: 5130
	protected float particlesScaleMult;

	// Token: 0x0400140B RID: 5131
	private const int impactParticleCount = 40;
}
